//
//  TaskDetailViewController.m
//  qdSubway
//
//  Created by andi911 on 2019/5/30.
//  Copyright © 2019 andi911. All rights reserved.
//

#import "TaskDetailViewController.h"

@interface TaskDetailViewController ()
//
@property (nonatomic,strong) UIScrollView *scrollView;

@end

@implementation TaskDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"任务详情";
    self.view.backgroundColor = [UIColor whiteColor];
    [self loadSetUpUI];
}

- (void)loadSetUpUI{
    [self.view addSubview:self.scrollView];
    
    UILabel *titlteLab = [[UILabel alloc]init];
    titlteLab.width = Screen_W - 40;
    titlteLab.text = @"任务标题任务标题任务标题任务标题任务标题任务标题任务标题";
    titlteLab.font = [UIFont boldSystemFontOfSize:18];
    CGFloat height = [titlteLab.text cly_stringHeightWithFont: titlteLab.font width:titlteLab.width];
    titlteLab.height = height;
    if (titlteLab.height>20) {
        titlteLab.numberOfLines = 2;
    }
    titlteLab.center = CGPointMake(20+titlteLab.width/2, 25+titlteLab.height/2);
    [self.scrollView addSubview:titlteLab];

    UIImageView *leftImage = [[UIImageView alloc]initWithImage:CLYImage(@"left_panddIma")];
    leftImage.center = CGPointMake(leftImage.width/2, 25+leftImage.height/2);
    [self.scrollView addSubview:leftImage];
    
    UILabel *taskInstruLa = [[UILabel alloc]init];
    taskInstruLa.text = @"*任务说明";
    taskInstruLa.width = Screen_W-40;
    taskInstruLa.height = 18;
    taskInstruLa.font = CLYFont(18);
    taskInstruLa.center = CGPointMake(20+taskInstruLa.width/2, titlteLab.bottom+20+taskInstruLa.height/2);
    [self.scrollView addSubview:taskInstruLa];
    NSString *str = @"说明说明进行公园广场环境保洁活动，清扫该地垃圾、杂物;保持环境卫生，进行文明游园宣传等活动多久啊空间的大大";
    
    UILabel *contentLab = [[UILabel alloc]init];
    contentLab.text = str;
    contentLab.width = Screen_W -40;
    contentLab.font = CLYFont(16);
    contentLab.numberOfLines = 0;
    contentLab.textColor = [UIColor grayColor];
    contentLab.height = [contentLab.text cly_stringHeightWithFont:CLYFont(16) width:contentLab.width];
    contentLab.center = CGPointMake(Screen_W/2, taskInstruLa.bottom+15+contentLab.height/2);
    [self.scrollView addSubview:contentLab];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(20, contentLab.bottom+17, Screen_W-40, 0.5)];
    line.backgroundColor = [UIColor lightGrayColor];
    [self.scrollView addSubview:line];
    
    NSArray *titleArr = @[@"*领取人数",@"*任务时间",@"*任务奖励"];
    NSArray *contentArr = @[@"10/100",@"2019-11-12至2019-12-12",@"20积分"];
    for (int i = 0; i<3; i++) {
        UILabel *taskInstruLa = [[UILabel alloc]init];
        taskInstruLa.text = titleArr[i];
        taskInstruLa.width = Screen_W-40;
        taskInstruLa.height = 18;
        taskInstruLa.font = CLYFont(18);
        taskInstruLa.center = CGPointMake(20+taskInstruLa.width/2, line.bottom+20+taskInstruLa.height/2+80*i);
        [self.scrollView addSubview:taskInstruLa];
        
        if (i<2){
            UIView *tline = [[UIView alloc]initWithFrame:CGRectMake(20, line.bottom+80+80*i, Screen_W-40, 0.5)];
            tline.backgroundColor = [UIColor lightGrayColor];
            [self.scrollView addSubview:tline];
        }

        UILabel *contentLa = [[UILabel alloc]init];
        contentLa.text = contentArr[i];
        contentLa.width = Screen_W-40;
        contentLa.height = 16;
        contentLa.textColor = [UIColor lightGrayColor];
        contentLa.font = CLYFont(16);
        contentLa.center = CGPointMake(20+contentLa.width/2, taskInstruLa.bottom+10+contentLa.height/2);
        [self.scrollView addSubview:contentLa];
        
    }
    
//    self.scrollView.backgroundColor = [UIColor redColor];
    
    UIButton *bottomBtn = [[UIButton alloc]init];
    bottomBtn.width = Screen_W - 40;
    bottomBtn.height = 44;
    bottomBtn.layer.cornerRadius = 22;
    bottomBtn.layer.masksToBounds = YES;
    bottomBtn.backgroundColor = RGBACOLOR(37, 184, 66);
    [bottomBtn setTitle:@"领取" forState:0];
    [bottomBtn addTarget:self action:@selector(tapBottomBtn) forControlEvents:1<<6];
    bottomBtn.center =  CGPointMake(Screen_W/2, self.scrollView.bottom+20+bottomBtn.height/2);
    [self.view addSubview:bottomBtn];
    
}

- (void)tapBottomBtn{
    DLog(@"你点击了领取按钮");
}


- (UIScrollView *)scrollView{
    if(!_scrollView){
        UIScrollView *tempScrollView = [[UIScrollView alloc]init];
        tempScrollView.width = Screen_W;
        tempScrollView.height = Screen_H-(getRectNavAndStatusHight)-40-44;
        tempScrollView.center = CGPointMake(Screen_W/2, getRectNavAndStatusHight+tempScrollView.height/2);
        tempScrollView.scrollEnabled = YES;
        tempScrollView.contentSize = CGSizeMake(Screen_W, Screen_H-getRectNavAndStatusHight-40-44-100);
        _scrollView = tempScrollView;
    }
    return _scrollView;
}

@end
